package com.dhcc.android.base.utils;

import android.app.Dialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.preference.PreferenceManager;

import com.dhcc.android.base.common.bean.KeyValueBean;
import com.dhcc.android.base.common.bean.Node;
import com.dhcc.android.base.common.bean.Period;
import com.dhcc.android.base.common.bean.Table;
import com.dhcc.android.base.common.bean.Task;
import com.dhcc.android.base.common.bean.Town;
import com.dhcc.android.base.common.bean.Village;
import com.dhcc.android.base.common.view.MyLoadingDialog;
import com.dhcc.android.base.db.DBManagerUtil;
import com.dhcc.android.base.utils.version.UpdataInfo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import srs.Display.Symbol.ISymbol;
import srs.Display.Symbol.SimpleFillStyle;
import srs.Display.Symbol.SimpleFillSymbol;
import srs.Display.Symbol.SimpleLineStyle;
import srs.Display.Symbol.SimpleLineSymbol;
import srs.Geometry.IEnvelope;
import srs.Geometry.IGeometry;
import srs.Geometry.IPoint;
import srs.Layer.CommonLayer;
import srs.Rendering.CommonClassBreakRenderer;


/**
 * 项目全局变量
 * 
 * @author pengling
 * @date 2014年8月29日
 */
public class Constants {

    //public static final String versionUrl = "http://124.207.115.119:6000/SurveyPlusAPP/surveyPlus_version.xml";//国家版本
    //public static final String versionUrl = "http://124.207.115.119:6000/SurveyPlusAPP/surveyPlus_version_ZJ.xml";//浙江版本
    //public static final String versionUrl = "http://124.207.115.119:6000/SurveyPlusAPP/surveyPlus_version_GX.xml";//广西版本
    public static UpdataInfo info;
    public static boolean needUpdate = false;//需要更新
    
    
    
    public static boolean clickFlag = true;
    
    /** 图斑类型--值 */
    public static KeyValueBean oldTBLX;
    
    //产量调查--估产作物列表
    public static List<Map<String, String>> zwList = new ArrayList<Map<String,String>>();
    public static Map<String, String> zwMap;
    //图纸拍摄
    public static Map<String, String> tzps_parent = null;
    public static Task tzps_task = null;
    public static Node tzps_node = null;
    
	// */返回码
	public static final String success = "0000";
	public static final String sys_error = "9999";
	public static final String no_user = "9006";
	public static final String md5_error = "9000";
	public static final String too_long = "9001";

	public static boolean dkBack = false;
	
	// */本机

	/** 设备ID */
	public static String DEVICE_ID;

	/** */
	public static boolean isDialogBack = false;

	// */ 变量
	/** 选中的层级 */
	public static Map<String, String> select;
	/** */
	public static final String LOCATION = "location";
	/** */
	public static final String SortBeanTypeByField = "fieldSet";
	/** */
	public static final String SortBeanTypeByABC = "abc";
	/** */
	public static final String GPSFLAG = "gpsflag";
	/** */
	public static String GPS = "";
	/** */
	public static final String LOCATION_ACTION = "locationAction";
	// */登录
	/** 注册状态 */
	public static boolean isRegistered = false;
	/** 用户ID */
	public static String USERID = null;
	/** 用户名 */
	public static String USERNAME = null;
	/** 密码 */
	public static String PASSWORD = null;
	/** IP地址 */
	public static String host = "114.242.219.11";
	/** 端口号 */
	public static String port = "8081";
	/** 登陆接口拼接地址 */
	public static String loginUrl = "/HttpInterFace/LoginCheck.ashx?USERNAME=dibinbin&PASSWORD=123456";
	/** MD5 */
	public static final String KEY = "83#14zj247";

	// */导航
	/** 导航目标 */
	public static Map<Integer, String> targets = new HashMap<Integer, String>();

	/**
	 * 导航目标点
	 * 
	 * added by 李忠义 20150616
	 */
	public static double[] TargetXY = new double[2];
	/**
	 * 图上选中的位置 added by lizhongyi 20150621
	 */
	public static IPoint TargetPointTouch = null;
	/** 上一层级 layer */
	public static List<String> players = new ArrayList<String>();

	public static List<Integer> positons = new ArrayList<Integer>();
	/** 当前选择的层级 */
	public static List<Map<String, String>> selects = new ArrayList<Map<String, String>>();
	/** 地图缩放范围 */
	public static Map<Integer, IEnvelope> envelopes = new HashMap<Integer, IEnvelope>();
	/** 层级目录列表集合 */
	public static List<Node> nodelist;

	// */ 当前信息
	/** 当前任务 */
	public static Task currentTask = null;
	/** 当前任务包根路径 */
	public static Task currentRootPath = null;
	/** 当前周期 */
	public static Period currentCycle;
	/** 当前表 */
	public static Table currentTable;
	/** 省 */
	public static String currentProvince = "";
	/** 市 */
	public static String currentCity = "";
	/** 县 */
	public static String currentCounty = "";
	/** 乡镇 */
	public static Town currentTown;
	/** 村 */
	public static Village currentVillage;

	public static boolean ATT_DOWNLOAD_FLAG = true;
	public static boolean data_refresh = false;
	// */ 状态标记
	/** */
	public static int screenWidth;
	/** */
	public static int screenHight;
	/**自然地块占位图片*/
	public static Bitmap ZRDKBITMAP;
	/** 服务器端口 */
	public static String UTIL_URL = "";
	/** 底部菜单高度 */
	public static int bottom_bar_Hight;
	/** 判断是否需要重新连接服务器 */
	public static boolean NET_FLAG = false;
	/** */
	public static int EXIT_FLAG = 0;
	// */
	// */ 常量标记
	/** ListView的分页页数 */
	public static final int PAGESIZE = 5;//
	// */ 系统默认
	/** 系统默认ip */
	public static final String Config_Address[] = { "127.0.0.1:8080",
			"127.0.0.2:8080", "127.0.0.3:8080" };
	// */ 任务属性填报
	/** */
	public static String currentCount = "";
	/** 填报主页的模块 */
	public static com.dhcc.android.base.common.bean.Config Config = null;//
	/** 显示在本页 */
	public static final String SELF = "SELF";
	/** 显示在新页 */
	public static final String NEW = "NEW";
	/** 列表数据添加 */
	public static final String SELECT = "SELECT";
	public static Dialog DIALOG = null;
	/** RadioPageView 停在的页面标签 */
	public static int radioPageViewFlag = 0;
	/** 选项非空的跳转 */
	public static int radioNullCheck = 0;
	/** RadioPageView 停在的页面标签 */
	public static String takePhotoFlag = "";

	/** 空间信息 */
	public static List<IGeometry> geometrys = new ArrayList<IGeometry>();//
	/** 空间信息需要显示的标注 */
	public static List<String> displayLableNames = new ArrayList<String>();
	/** 空间信息的分段渲染
	 * 
	 */
	public static List<Double> displayRenderBreaks = new ArrayList<Double>();

	public static List<Integer> rowidList = new ArrayList<Integer>();

	public static IGeometry geometry;
	/** */
	public static CommonLayer COMMONLAYER;
	
	
	public static String YFBHU;
	// */ CommenLayer的样式
	public static ISymbol SYMBOLCBJ = new SimpleFillSymbol(Color.argb(64, 255,
			255, 0), new SimpleLineSymbol(Color.argb(255, 255, 255, 0), 2,
			SimpleLineStyle.Solid), SimpleFillStyle.Hollow, Color.argb(0,
			255, 255, 0));
	
	// */ CommenLayer的样式 完成调查
	public static ISymbol SYMBOLCBJWC = new SimpleFillSymbol(Color.argb(128, 255,
				255, 22), new SimpleLineSymbol(Color.argb(255, 255, 255, 0), 2,
				SimpleLineStyle.Solid), SimpleFillStyle.Soild, Color.argb(0,
				0,255,0));

	public static DBManagerUtil dbManagerUtil;
	/** 调查完成的数据库路径--null */
	public static String surveyDKIDPathNoData;
	/** 调查成果路径 */
	public static String surveyPath;
	/** 调查成果图片信息路径 */
	public static String surveyPhotoPath;
	/**
	 * 调查完成的数据库路径--/SURVEY/DKIDxxxx/DATA.db
	 */
	public static String surveyDKIDPath;
	/**
	 * 地块ID
	 */
	public static String DKID = "";
	/**
	 * 空间信息全局变量
	 */
	public final static String GEO = "GEO";
	/**
	 * 调查包DEMAND路径
	 */
	public static String path;
	
	/**CommenLayer的样式的分段渲染
	 * 
	 */
	public static CommonClassBreakRenderer RENDERCBJ = new CommonClassBreakRenderer();
	
	
	public static String new_PhotoName = null;

	public static boolean isNetworkAvailable(Context context) {
		ConnectivityManager cm = (ConnectivityManager) context
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		if (cm == null) {
		} else {
			// 如果仅仅是用来判断网络连接　　　　　　
			// 则可以使用 cm.getActiveNetworkInfo().isAvailable();
			NetworkInfo[] info = cm.getAllNetworkInfo();
			if (info != null) {
				for (int i = 0; i < info.length; i++) {
					if (info[i].getState() == NetworkInfo.State.CONNECTED
							|| info[i].getState() == NetworkInfo.State.CONNECTING) {
						return true;
					}
				}
			}
		}
		return false;
	}

	/** MIME类型 */
	public static final String[][] MIME_MapTable = {
			// {后缀名，MIME类型}
			{ ".bmp", "image/bmp" },
			{ ".doc", "application/msword" },
			{ ".docx",
					"application/vnd.openxmlformats-officedocument.wordprocessingml.document" },
			{ ".xls", "application/vnd.ms-excel" },
			{ ".xlsx",
					"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" },
			{ ".exe", "application/octet-stream" },
			{ ".gif", "image/gif" },
			{ ".gtar", "application/x-gtar" },
			{ ".gz", "application/x-gzip" },
			{ ".htm", "text/html" },
			{ ".html", "text/html" },
			{ ".jar", "application/java-archive" },
			{ ".java", "text/plain" },
			{ ".jpeg", "image/jpeg" },
			{ ".jpg", "image/jpeg" },
			{ ".js", "application/x-javascript" },
			{ ".log", "text/plain" },
			{ ".pdf", "application/pdf" },
			{ ".png", "image/png" },
			{ ".ppt", "application/vnd.ms-powerpoint" },
			{ ".pptx",
					"application/vnd.openxmlformats-officedocument.presentationml.presentation" },
			{ ".prop", "text/plain" }, { ".tar", "application/x-tar" },
			{ ".tgz", "application/x-compressed" }, { ".txt", "text/plain" },
			{ ".wps", "application/vnd.ms-works" }, { ".xml", "text/plain" },
			{ ".zip", "application/x-zip-compressed" }, { "", "*/*" } };
	
	
	
	public static List<Map<String, String>> setListToList(List<Map<String, String>> oldList,List<Map<String, String>> newList){
        newList.clear();
        for (Map<String, String> map : oldList) {
            newList.add(map);
        }
	    
	    return newList;
    }

	
	private static Dialog loadingdialog;
	
	public static void showDialog(Context context,String msg){
	    loadingdialog = MyLoadingDialog.createLoadingDialog(context, msg);
	    loadingdialog.show();
	}
	
	public static void closeDialog(){
	    if(loadingdialog != null && loadingdialog.isShowing()){
	        loadingdialog.dismiss();
	    }
	}
	
	
    public static boolean isListEmpty(List list){
        if(list == null || list.size() == 0){
            return true;
        }
        return false;
    }
	
    
    //================常用数据=================
    
    

    //存储全局公用数据
    public static void saveTempData(Context ctx,String key,String value){
        SharedPreferences settings = PreferenceManager
                .getDefaultSharedPreferences(ctx);
        SharedPreferences.Editor edit = settings.edit();
        edit.putString(key, value);
        edit.commit();
    }
    
    //获取全局公用数据
    public static String getTempData(Context ctx,String key){
        SharedPreferences settings = PreferenceManager
                .getDefaultSharedPreferences(ctx);
        return settings.getString(key, "");
    }

    
    
}
